<?php
namespace app\merchant\controller;

use app\admin\model\User;
use app\admin\model\UserMerchant;
use app\common\BaseController;
use app\index\model\Users;
use app\mall\model\MallGoodsCate;
use think\Controller;
use think\facade\View;
use think\exception\HttpResponseException;

class Base extends BaseController
{

    protected $uid;
    protected $user_info;

    public function initialize()
    {
      $userID = $this->app->session->get('uid');
      if($userID){
        $this->uid = $userID;
        $userInfo = UserMerchant::where('id', $userID)->where('status',1)->find();
        $this->user_info = $userInfo;
        View::assign('userInfo',$userInfo);
      }
      View::assign('is_login', (isset($userID) && $userID > 0) ? true : false);
      View::assign('controller', strtolower(request()->controller()));
      View::assign('action', strtolower(request()->action()));
      View::assign('routers',strtolower(request()->controller()) . '/' . strtolower(request()->action()));
      $this->check_login();
    }

      /**
     * @name:检查登录
     * @author:Sam
     * @date:2024-09-02
     * @param:[string] param [desc]
    */
    public function  check_login(){
      $userID = $this->app->session->get('uid');
      if(empty($userID)){
        header('Location: ' . url('/merchant/login'));
        exit;
      }
    }


     /**
     * URL重定向
     * @param string $url 跳转链接
     * @param integer $code 跳转代码
     */
    public function redirect(string $url, int $code = 302): void
    {
        throw new HttpResponseException(redirect($url, $code));
    }
}
